package com.imooc.girl.controller;

import com.imooc.girl.domain.*;
import com.imooc.girl.service.GradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Calendar;
import java.util.List;
import java.util.Map;
import java.util.Set;

@RestController
public class GradeController {
    @Autowired
    private GradeService gradeService;
    @PostMapping(value = "grades")
    public ReturnResult grades(GradesForm gradesForm)throws Exception{
        if(gradesForm.getCurrentPage()<1){
            throw new Exception("当前页必须存在");
        }else if(gradesForm.getPageSize()<=0){
            throw new Exception("页面大小必须大于0");
        }else if(gradesForm.getScoreUpperBound()<gradesForm.getScoreLowerBound()){
            throw new Exception("分数上界必须大于分数下界");
        }else{
            if(gradesForm.getScoreUpperBound()==0)
                gradesForm.setScoreUpperBound(100);
            return gradeService.gradesService(gradesForm);
        }
    }
    @PostMapping(value = "gradesoptions")
    public ReturnResult gradesOptions(GradesOptionsForm form){
       return gradeService.gradesOptionsService(form);
    }
}
